<template>
  <div class="app-container">
    <!-- 搜索 -->
    <el-card class="search-card">
      <el-form
        size="small"
        :model="queryParams"
        ref="queryForm"
        class="formBox"
        label-width="88px"
      >
        <el-row :gutter="0">
          <el-col :span="5">
            <el-form-item label="姓名" prop="personName">
              <el-input
                placeholder="请输入姓名"
                v-model="queryParams.personName"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="身份证号" prop="idNumber">
              <el-input
                placeholder="请输入身份证号"
                v-model="queryParams.idNumber"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="年级名称" prop="gradeId">
              <el-select
                v-model="queryParams.gradeId"
                placeholder="请选择年级名称"
                style="width: 100%"
                @change="gradeFun"
              >
                <el-option
                  v-for="(item, index) in gradeList"
                  :key="index"
                  :value="item.id"
                  :label="item.gradeName"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="班级" prop="classId">
              <el-select
                v-model="queryParams.classId"
                placeholder="请选择班级"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in classList"
                  :key="index"
                  :value="item.id"
                  :label="item.className"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="5">
            <el-form-item label="团餐计划" prop="gradeId">
              <el-select
                v-model="queryParams.status"
                placeholder="请选择团餐计划"
                
                style="width: 100%"
              >
                <el-option value="1" label="开启"></el-option>
                <el-option value="2" label="关闭"></el-option>
              </el-select>
            </el-form-item>
          </el-col> -->
          <el-col :span="5">
            <el-form-item label="餐别类型" prop="diningName">
              <el-input v-model="queryParams.diningName" placeholder="请输入餐别">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="餐标类型" prop="mealType">
              <el-select
                v-model="queryParams.mealType"
                placeholder="请选择餐标类型"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in queryListSchoolMealTypeData"
                  :key="index"
                  :value="item.id"
                  :label="item.mealType"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="支付状态" prop="status">
              <el-select
                v-model="queryParams.status"
                placeholder="请选择支付状态"
                style="width: 100%"
              >
                <el-option value="0" label="未交易"></el-option>
                <el-option value="1" label="成功"></el-option>
                <el-option value="2" label="交易中"></el-option>
                <el-option value="3" label="交易失败"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="5">
            <el-form-item label="缴费方式" prop="gradeId">
              <el-select
                v-model="queryParams.status"
                placeholder="请选择缴费方式"
                
                style="width: 100%"
              >
                <el-option value="1" label="开启"></el-option>
                <el-option value="2" label="关闭"></el-option>
              </el-select>
            </el-form-item>
          </el-col> -->
          <el-col :span="8">
            <el-form-item label="供餐日期" prop="time">
              <el-date-picker
                v-model="queryParams.time"
                type="datetimerange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                format="yyyy-MM-dd HH:mm:ss"
                value-format="yyyy-MM-dd HH:mm:ss"
                :default-time="['00:00:00', '23:59:59']"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <div class="dis aic">
                <div class="flex_1"></div>
                <el-button
                  type="primary"
                  icon="el-icon-search"
                  size="mini"
                  @click="handleQuery"
                >
                  搜索
                </el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">
                  重置
                </el-button>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <el-card class="search-card">
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['teamMeal:finance:orderDetails:export']"
          >
            导出
          </el-button>
        </el-col>
        <right-toolbar
          :showSearch.sync="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-row>
    </el-card>
    <el-card class="table-card">
      <el-table :data="dataList">
        <!-- <el-table-column label="校区" align="center" prop="name" /> -->
        <!-- <el-table-column label="团餐计划" align="center" prop="idCardNumber" /> -->
        <el-table-column label="供餐日期" align="center" prop="diningTime" />
        <el-table-column label="年级" align="center" prop="gradeName" />
        <el-table-column label="班级" align="center" prop="className" />
        <el-table-column label="学生姓名" align="center" prop="personName" />
        <el-table-column label="学生身份证号" align="center" prop="idNumber" />
        <el-table-column label="餐标价格（元）" align="center" prop="totalMoney" />
        <!-- <el-table-column label="应付金额" align="center" prop="totalMoney" />
        <el-table-column label="实缴金额" align="center" prop="idCardNumber" /> 
       <el-table-column label="是否折扣" align="center" prop="idCardNumber" /> 
         <el-table-column label="折扣" align="center" prop="idCardNumber" /> -->
        <el-table-column label="餐别" align="center" prop="diningName" />
        <el-table-column label="餐标类型" align="center" prop="mealType">
          <template slot-scope="scope">
            <span v-if="scope.row.mealType == 1">早餐</span>
            <span v-if="scope.row.mealType == 2">午餐</span>
            <span v-if="scope.row.mealType == 3">晚餐</span>
          </template>
        </el-table-column>
        <el-table-column label="餐标缴费方式" align="center" prop="idCardNumber">
          <template slot-scope="scope">
            <span>笔笔扣款</span>
          </template>
        </el-table-column>
        <el-table-column label="支付状态" align="center" prop="status">
          <template slot-scope="scope">
            <span v-if="scope.row.status == 0">未交易</span>
            <span v-if="scope.row.status == 1">成功</span>
            <span v-if="scope.row.status == 2">交易中</span>
            <span v-if="scope.row.status == 3">交易失败</span>
          </template>
        </el-table-column>
        <!-- <el-table-column label="账单状态" align="center" prop="idCardNumber" /> -->
        <!-- <el-table-column label="用户留言" align="center" prop="idCardNumber" /> -->
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
  </div>
</template>
<script>
import { listGrade } from "@/api/campus/grade";
import { listClassManage } from "@/api/campus/classManage";
import { selectTeamDiningOrderDetails } from "@/api/teamMeal/finance";
import { queryListSchoolMealType } from "@/api/teamMeal/mealStandard";
export default {
  name: "financeOrderDetails",
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 1,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        personName: null,
        idNumber: null,
        gradeId: null,
        classId: null,
        diningName: null,
        mealType: null,
        status: null,
        time: [],
        startTime: null,
        endTime: null,
      },
      dataList: [],
      campusList: [],
      gradeList: [],
      classList: [],
      queryForm: {},
      queryListSchoolMealTypeList: [],
    };
  },
  "queryParams.time": function (newVal) {
    console.log(newVal);
    if (!newVal) {
      this.queryParams.time = [];
      this.queryParams.startTime = null;
      this.queryParams.endTime = null;
    }
  },
  created() {
    this.listGradeFun();
    this.getList();
    this.queryListSchoolMealTypeFun();
  },
  activated() {
    this.listGradeFun();
    this.getList();
    this.$forceUpdate();
    this.queryListSchoolMealTypeFun();
  },
  methods: {
    // 列表
    getList() {
      if (this.queryParams.time.length == 2) {
        this.queryParams.startTime = this.queryParams.time[0];
        this.queryParams.endTime = this.queryParams.time[1];
      }
      selectTeamDiningOrderDetails(this.queryParams).then((res) => {
        if (res.code == 200) {
          this.dataList = res.rows;
          this.total = res.total;
        }
      });
    },
    queryListSchoolMealTypeFun() {
      queryListSchoolMealType({}).then((res) => {
        if (res.code == 200) {
          this.queryListSchoolMealTypeList = res.rows;
        }
      });
    },
    /**
     * 获取成绩列表
     *
     * @param options 包含校区ID的对象
     */
    listGradeFun(options) {
      listGrade({ pageNum: 1, pageSize: 200, campusId: options }).then((res) => {
        if (res.code == 200) {
          this.gradeList = res.rows;
        }
      });
    },
    /**
     * 获取班级列表
     *
     * @param options - 年级ID
     */
    gradeFun(options) {
      this.$set(this.queryParams, "classId", "");
      listClassManage({ pageNum: 1, pageSize: 200, gradeId: options }).then(
        (response) => {
          this.classList = response.rows;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.time = [];
      this.queryParams.startTime = null;
      this.queryParams.endTime = null;

      this.handleQuery();
    },
    // 导出
    handleExport() {
      this.download(
        "/diningOrder/exportAcquisition",
        {
          ...this.queryParams,
        },
        `订单明细导出.xlsx`
      );
    },
  },
};
</script>
<style>
.padding_4_10 {
  padding: 4px 10px !important;
}

.formBox >>> .el-form-item--small.el-form-item {
  margin-bottom: 0px !important;
}

.formBox >>> .el-form-item__label {
  font-size: 12px !important;
  padding: 0 !important;
}
</style>
